<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Selenium IDE Test</title>
    <link rel="stylesheet" type="text/css" href="chrome://selenium-ide/content/jsunit/css/jsUnitStyle.css">
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/lib/prototype.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/scripts/htmlutils.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/scripts/atoms.js"/></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/scripts/selenium-browserbot.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/jsunit/app/jsUnitCore.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/preferences.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/tools.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/file-utils.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/options.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/format.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/testCase.js"></script>
		<script type="text/javascript" src="test-api-doc.js"></script>
		<script type="text/javascript">
function setUp() {
}

function testNewTestCaseShouldHaveUntitledTitle() {
	var testCase = new TestCase();
  assertEquals("Untitled", testCase.getTitle());
}

function testGetCommandIndexByTextIndex() {
	var formats = new FormatCollection(OPTIONS);
	var testCase = new TestCase();
	testCase.commands.push(new Command("open", "http://www.google.com/"));
	testCase.commands.push(new Command("click", "foo"));
	testCase.commands.push(new Command("assertText", "foo", "bar"));
	var format = formats.selectFormat("perl-rc");
	var source = format.getFormatter().format(testCase);

	assertEquals(0, testCase.getCommandIndexByTextIndex(source, source.indexOf("open"), format.getFormatter()));
	assertEquals(1, testCase.getCommandIndexByTextIndex(source, source.indexOf("click"), format.getFormatter()));
	assertEquals(2, testCase.getCommandIndexByTextIndex(source, source.indexOf("text_is"), format.getFormatter()));
	assertEquals(3, testCase.getCommandIndexByTextIndex(source, source.length, format.getFormatter()));

	// parse again
	var header = testCase.formatLocal("perl-rc").header;
	var headerLines = header.split(/\n/).length - 1;
	format.getFormatter().parse(testCase, source);
	// Now testCase.commands should consist of multiple Line objects
	assertEquals(headerLines, testCase.getCommandIndexByTextIndex(source, source.indexOf("open"), format.getFormatter()));
	assertEquals(headerLines + 1, testCase.getCommandIndexByTextIndex(source, source.indexOf("click"), format.getFormatter()));
}
</script>
  </head>

  <body>
  </body>
</html>
